﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Amplify.Twitter
{

	/// <summary>
	/// A boolean Xml Repsonse that comes over as a root node, i.e. &lt;root&gt;true&lt;/root&gt;
	/// </summary>
	[Serializable]
	public class BooleanXmlResponse : XmlResponse 
	{
		/// <summary>
		/// Gets or sets a value indicating whether this <see cref="BooleanXmlResponse"/> is response.
		/// </summary>
		/// <value><c>true</c> if response; otherwise, <c>false</c>.</value>
		public bool Response { get; set; }

		/// <summary>
		/// Gets the name of the root.
		/// </summary>
		/// <value>The name of the root.</value>
		public virtual  string RootName {
			get { return "root"; }
		}

		/// <summary>
		/// Generates an object from its XML representation.
		/// </summary>
		/// <param name="reader">The <see cref="T:System.Xml.XmlReader"/> stream from which the object is deserialized.</param>
		public override void ReadXml(System.Xml.XmlReader reader)
		{
			reader.MoveToContent();
			reader.Read();
			this.Response = reader.ReadContentAsBoolean();
		}

		/// <summary>
		/// Converts an object into its XML representation.
		/// </summary>
		/// <param name="writer">The <see cref="T:System.Xml.XmlWriter"/> stream to which the object is serialized.</param>
		public override void WriteXml(System.Xml.XmlWriter writer)
		{
			writer.WriteElementString(this.RootName, this.Response ? "true" : "false");
		}

	}
}
